package com.struc.td;

import com.badlogic.gdx.Gdx;

public class GuiTester {
	private Main main;
	private Game game;
	private MainMenu mainMenu;
	private int curTest;
	/* A gui tester that will pretend to call
	 * touchDown / touchUp methods and make
	 * sure the result is as it should be.
	 */
	public GuiTester(Main main) {
		this.main = main;
		curTest = -4;
		game = ((Game) main.getState(2));
		mainMenu = ((MainMenu) main.getState(1));
	}
	public void runNextTest() {
		if (curTest == -4) {
			mainMenu.touchDown(151, 147, 0, 0);
			if (main.activeState instanceof Highscore) {
				Gdx.app.log("Gui Tester","Test -3: Entering highscore, Completed");
			} else {
				Gdx.app.log("Gui Tester","Test -3: Entering highscore, Failed");
			}
			curTest++;
		} else if (curTest == -3) {
			main.getState(3).touchDown(150, 197, 0,0);
			if (main.activeState instanceof MainMenu) {
				Gdx.app.log("Gui Tester","Test -2: Entering main menu from highscore, Completed");
			} else {
				Gdx.app.log("Gui Tester","Test -2: Entering main menu from highscore, Failed");
			}
			curTest++;
		} else if (curTest == -2) {
			boolean curSound = Sounds.getMuted(); 
			mainMenu.touchDown(136,211,0,0);
			if (curSound != Sounds.getMuted()) {
				Gdx.app.log("Gui Tester","Test -1: Toggle sound, Completed");
			} else {
				Gdx.app.log("Gui Tester","Test -1: Toggle sound, Failed");
			}
			curTest++;
		} else if (curTest == -1) {
			boolean curSound = Sounds.getMuted(); 
			mainMenu.touchDown(136,211,0,0);
			if (curSound != Sounds.getMuted()) {
				Gdx.app.log("Gui Tester","Test 0: Toggle sound, Completed");
			} else {
				Gdx.app.log("Gui Tester","Test 0: Toggle sound, Failed");
			}
			curTest++;
		} else if (curTest == 0) {
			mainMenu.touchDown(174, 84, 0, 0);
			if (main.activeState instanceof Game) {
				Gdx.app.log("Gui Tester","Test 1: Entering game, Completed");
			} else {
				Gdx.app.log("Gui Tester","Test 1: Entering game, Failed");
			}
			curTest++;
		} else if (curTest == 1) {
			game.touchDown(253,33,0,0);
			game.touchUp(253,33,0,0);
			if (game.getActiveEntity() instanceof TowerSpace) {
				Gdx.app.log("Gui Tester","Test 2: Clicking a tower space, Completed");
			} else {
				Gdx.app.log("Gui Tester","Test 2: Clicking a tower space, Failed");
			}
			curTest++;
		} else if (curTest == 2) {
			game.touchDown(234,122,0,0);
			if (game.getTowers().size == 1) {
				Gdx.app.log("Gui Tester","Test 3: Building a damage tower, Completed");
			} else {
				Gdx.app.log("Gui Tester","Test 3: Building a damage tower, Failed");
			}
			curTest++;
		} else if (curTest == 3) {
			game.touchDown(253,33,0,0);
			game.touchUp(253,33,0,0);
			if (game.getActiveEntity() instanceof TowerDamage) {
				Gdx.app.log("Gui Tester","Test 4: Clicking a damage tower, Completed");
			} else {
				Gdx.app.log("Gui Tester","Test 4: Clicking a damage tower, Failed");
			}
			curTest++;
		} else if (curTest == 4) {
			game.touchDown(241,206,0,0);
			curTest++;
		} else if (curTest == 5) {
			if (game.getPlayer().getGold() == 425 && game.getActiveEntity() == null && game.getTowers().size == 0) {
				Gdx.app.log("Gui Tester","Test 5: Selling a damage tower, Completed");
			} else {
				Gdx.app.log("Gui Tester","Test 5: Selling a damage tower, Failed");
			}
			curTest++;
		} else if (curTest == 6) {
			game.touchDown(253,33,0,0);
			game.touchUp(253,33,0,0);
			curTest++;
		} else if (curTest == 7) {
			game.touchDown(250,160,0,0);
			curTest++;
		} else if (curTest == 8) {
			game.touchDown(253,33,0,0);
			game.touchUp(253,33,0,0);
			if (game.getActiveEntity() instanceof TowerSlow) {
				Gdx.app.log("Gui Tester","Test 6: Building a slow tower, Completed");
			} else {
				Gdx.app.log("Gui Tester","Test 6: Building a slow tower, Failed");
			}
			curTest++;
		} else if (curTest == 9) {
			game.touchDown(234,201,0,0);
			if (game.getPlayer().getGold() == 400 && game.getActiveEntity() == null) {
				Gdx.app.log("Gui Tester","Test 7: Selling a slow tower, Completed");
			} else {
				Gdx.app.log("Gui Tester","Test 7: Selling a slow tower, Failed");
			}
			curTest++;
		} else if (curTest == 10) {
			game.touchDown(253,33,0,0);
			game.touchUp(253,33,0,0);
			curTest++;
		} else if (curTest == 11) {
			game.touchDown(234,122,0,0);
			curTest++;
		} else if (curTest == 12) {
			game.touchDown(14,16,0,0);
			if (main.activeState instanceof Pause) {
				Gdx.app.log("Gui Tester","Test 8: Entering pause, Completed");
			} else {
				Gdx.app.log("Gui Tester","Test 8: Entering pause, Failed");
			}
			curTest++;
		} else if (curTest == 13) {
			main.getState(4).touchDown(166,84,0,0);
			if (main.activeState instanceof MainMenu) {
				Gdx.app.log("Gui Tester","Test 9: Entering main menu from pause, Completed");
			} else {
				Gdx.app.log("Gui Tester","Test 9: Entering main menu from pause, Failed");
			}
			curTest++;		
		} else if (curTest == 14) {
			main.getState(1).touchDown(162,95,0,0);
			if (main.activeState instanceof Game && game.getTowers().size == 1) {
				Gdx.app.log("Gui Tester","Test 10: Continue game, Completed");
			} else {
				Gdx.app.log("Gui Tester","Test 10: Continue game, Failed");
			}
			curTest++;		
		} else if (curTest == 15) {
			game.touchDown(14,16,0,0);
			curTest++;
		} else if (curTest == 16) {
			main.getState(4).touchDown(156,127,0,0);
			if (game.getTowers().size == 0) {
				Gdx.app.log("Gui Tester","Test 11: Restarting game, Completed");
			} else {
				Gdx.app.log("Gui Tester","Test 11: Restarting game, Failed");
			}
			curTest++;
		} else if (curTest == 17) {
			Gdx.app.log("Gui Tester","All tests ran. Exiting.");
			Gdx.app.exit();
			curTest++;
		}
	}
}
